import requests
from unittest import TestCase
from ddt import ddt, data, unpack

from TEST.Foot.data import Data


@ddt
class TestLogin(TestCase):

    session = requests.session()
    session.request('get', 'http://101.42.249.74:90/login/verifyLogin',
                         params={'username': 'lisi', 'password': 'e10adc3949ba59abbe56e057f20f883e'})

    def model(self, title, url, req, params, statu, expect, username=None):
        if username is not None:
            self.session.request('get', 'http://101.42.249.74:90/login/verifyLogin',
                             params={'username': username, 'password': 'e10adc3949ba59abbe56e057f20f883e'})

        print(title)
        print(params)

        req = req.lower()
        res = self.session.request(req, url, params=params)

        status = res.status_code
        code = res.json()

        expect = expect[expect.find(':') + 1:]

        if (status == 200):
            print('code')
            self.assertEqual(str(int(expect)), str(code['code']))

    # @data(*Data().data(epos=1))
    # @unpack
    # def test_login(self, title, url, req, params, statu, expect):
    #     self.model(title, url, req, params, statu, expect)

    # @data(*Data().data(10, epos=13))
    # @unpack
    # def test_buy(self, title, url, req, params, statu, expect):
    #     self.model(title, url, req, params, statu, expect, 'lisi')

    @data(*Data().data(24))
    @unpack
    def test_admin(self, title, url, req, params, statu, expect):
        self.model(title, url, req, params, statu, expect, 'admin')
